package com.eclink.asset.workflow.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eclink.asset.workflow.domain.dto.DoTaskDTO;
import com.eclink.asset.pojo.query.ApplyQuery;

import com.eclink.asset.workflow.domain.dao.Todo;
import com.eclink.asset.workflow.service.FlowService;
import com.eclink.asset.workflow.service.TodoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("代办接口列表")
@RestController
@RequestMapping("/todo")
public class TodoController {

    @Resource
    private TodoService todoService;

    @ApiOperation("显示审批任务的代办列表")
    @PostMapping("/approveList/{finish}")
    public ResponseEntity<Page<Todo>> approveList(@RequestBody ApplyQuery query, Pageable page, @PathVariable boolean finish) {
        IPage<Todo> pageData = todoService.getApproveList(page, finish);
        List<Todo> list = pageData.getRecords();
        return ResponseEntity.ok(new PageImpl<>(list, page, pageData.getTotal()));
    }

    @ApiOperation("显示入库的代办列表")
    @PostMapping("/employeeList")
    public ResponseEntity<Page<Todo>> employeeList(@RequestBody ApplyQuery query, Pageable page) {
        IPage<Todo> pageData = todoService.getEmployeeList(page);
        List<Todo> list = pageData.getRecords();
        return ResponseEntity.ok(new PageImpl<>(list, page, pageData.getTotal()));
    }

    @ApiOperation("显示入库的代办列表")
    @PostMapping("/transferList")
    public ResponseEntity<Page<Todo>> transferList(@RequestBody ApplyQuery query, Pageable page) {
        IPage<Todo> pageData = todoService.getTransferList(page);
        List<Todo> list = pageData.getRecords();
        return ResponseEntity.ok(new PageImpl<>(list, page, pageData.getTotal()));
    }

    @ApiOperation("同意代办任务")
    @PostMapping("/approveTask")
    public ResponseEntity<Integer> approveTask(@RequestBody Todo doTaskDTO) {
        doTaskDTO.setPass(1);
        todoService.doTodo(doTaskDTO);
        return ResponseEntity.ok(1);
    }

    @ApiOperation("驳回代办任务")
    @PostMapping("/rejectTask")
    public ResponseEntity<Integer> rejectTask(@RequestBody Todo doTaskDTO) {
        doTaskDTO.setPass(2);
        todoService.doTodo(doTaskDTO);
        return ResponseEntity.ok(1);
    }

}
